package com.astn.bks;

import java.io.Serializable;

import adstn.dialoglib.Dialog;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.astn.bks.util.BksConstants;
import com.paypal.android.MEP.PayPalResultDelegate;

public class PayPalDelegate implements PayPalResultDelegate, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Context context;

	public PayPalDelegate(Context context) {
		this.context = context;
	}

	@Override
	public void onPaymentCanceled(String paymentStatus) {
		Toast.makeText(context, "Payment cancel.", Toast.LENGTH_SHORT).show();
		((Activity) context).setResult(Activity.RESULT_CANCELED);
		((Activity) context).finish();
	}

	@Override
	public void onPaymentFailed(String paymentStatus, String correlationID,
			String payKey, String errorID, String errorMessage) {
		Dialog.showAlert(context, errorMessage + "\nError id: " + errorID
				+ "\nCorrelation ID: " + correlationID + "\nPay Key: " + payKey);
		((Activity) context).setResult(BksConstants.RESULT_ERROR);
		((Activity) context).finish();
	}

	@Override
	public void onPaymentSucceeded(String payKey, String paymentStatus) {
		Intent i = new Intent();
		i.putExtra(BksConstants.EXTRA_PAYKEY, payKey);
		((Activity) context).setResult(Activity.RESULT_OK, i);
		((Activity) context).finish();

	}

}
